from uuid import uuid4
from extensions import db


class User(db.Model):
    __tablename__ = "users"
    id = db.Column(
        db.String(36), primary_key=True, default=lambda: str(uuid4()), nullable=False
    )
    email = db.Column(db.String(255), nullable=False, unique=True, index=True)
    # 订阅的热点列表，JSON格式，{subscribed_hotspots: []}
    subscribed_hotspots = db.Column(
        db.JSON, default=[], nullable=False
    )
    # 配置项
    config = db.Column(db.JSON, default={}, nullable=False)
    # 打开链接的方式，是否为新窗口打开
    # open_in_new_window  true/false
    # 列表展示方式 0表示完整模式，1表示简洁模式
    # list_display 0/1

    def __repr__(self):
        return f"<User {self.email}>"
    
    def to_dict(self):
        return {
            "id": self.id,
            "email": self.email,
            "subscribed_hotspots": self.subscribed_hotspots,
            "config": self.config,
        }
